package com.szcinda.rpa.controller;

import com.szcinda.rpa.Result;
import com.szcinda.rpa.service.RunTask;
import com.szcinda.rpa.service.UserMachineDto;
import com.szcinda.rpa.service.UserMachineService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/machine")
public class MachineController {

    private final UserMachineService userMachineService;

    public MachineController(UserMachineService userMachineService) {
        this.userMachineService = userMachineService;
    }

    @PostMapping("run")
    public Result<String> run(@RequestBody RunTask runTask) {
        userMachineService.run(runTask);
        return Result.success();
    }

    @PostMapping("stop")
    public Result<String> stop(@RequestBody RunTask runTask) {
        userMachineService.stop(runTask);
        return Result.success();
    }

    @GetMapping("getMachines/{userName}")
    public List<UserMachineDto> getTasks(@PathVariable String userName) {
        return userMachineService.getMachineByUserName(userName);
    }


    @GetMapping("getRunTasks/{userName}")
    public List<RunTask> getRunTasks(@PathVariable String userName) {
        return userMachineService.getRunTasks(userName);
    }

    @GetMapping("del/{id}")
    public Result<String> deleteById(@PathVariable String id) {
        userMachineService.delete(id);
        return Result.success();
    }
}
